package co.edu.usbcali.egrapico.vista.ambient;

import co.edu.usbcali.egrapico.vista.FrmPrincipal;

public class LabelAsk extends javax.swing.JLabel implements java.io.Serializable {

    PanelAsk frame;
    String nameParent;
    private javax.swing.JTextField TextField;
    private javax.swing.JTextPane TextPane;
    private javax.swing.JButton cancel;
    private javax.swing.JPanel comment;
    private javax.swing.JInternalFrame frame2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel label;
    private javax.swing.JButton ok;
    private String toolTipText;
    private javax.swing.JMenuItem item1;
    private javax.swing.JMenuItem iten2;
    private javax.swing.JCheckBoxMenuItem iten3;
    private javax.swing.JMenuItem iten4;
    private javax.swing.JMenuItem iten5;
    private javax.swing.JMenuItem iten6;
    private javax.swing.JMenuItem iten7;
    private javax.swing.JSeparator separador;
    private javax.swing.JSeparator separador2;
    private javax.swing.JPopupMenu poput;
    boolean ban = false, ban1 = false;//,remove=false;
    private boolean clon = false;

    /**
     * Creates a new instance of LabelContext
     */
    public LabelAsk() {
        toolTipText = "";
        frame = new PanelAsk();
        nameParent = "";
        poput = new javax.swing.JPopupMenu();
        item1 = new javax.swing.JMenuItem();
        iten2 = new javax.swing.JMenuItem();
        separador = new javax.swing.JSeparator();
        iten3 = new javax.swing.JCheckBoxMenuItem();
        iten4 = new javax.swing.JMenuItem();
        iten5 = new javax.swing.JMenuItem();
        iten6 = new javax.swing.JMenuItem();
        separador2 = new javax.swing.JSeparator();
        iten7 = new javax.swing.JMenuItem();
        item1.setText("Properties...");
        item1.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item1ActionPerformed(evt);
            }
        });
        poput.add(item1);
        iten2.setText("Remove");
        iten2.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item2ActionPerformed(evt);
            }
        });
        poput.add(iten2);

        poput.add(separador);

        iten3.setText("Is Clon");
        iten3.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item3ActionPerformed(evt);
            }
        });
        poput.add(iten3);
        iten4.setText("Remove Consecuent");
        iten4.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item4ActionPerformed(evt);
            }
        });
        poput.add(iten4);
        iten5.setText("View Program");
        iten5.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item5ActionPerformed(evt);
            }
        });
        poput.add(iten5);
        iten6.setText("View Restrictions");
        iten6.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item6ActionPerformed(evt);
            }
        });
        poput.add(iten6);
        poput.add(separador2);

        iten7.setText("Open implication Panel");
        iten7.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                item7ActionPerformed(evt);
            }
        });
        poput.add(iten7);
        setComponentPopupMenu(poput);
        //definicion de las propiedades 
        frame2 = new javax.swing.JInternalFrame("",
                false, //resizable
                true, //closable
                false, //maximizable
                true);//iconifiable
        label = new javax.swing.JLabel();
        TextField = new javax.swing.JTextField();
        comment = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TextPane = new javax.swing.JTextPane();
        ok = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        frame2.getContentPane().setLayout(new java.awt.FlowLayout());
        frame2.setFrameIcon(null);
        frame2.setMaximumSize(new java.awt.Dimension(79, 43));
        frame2.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        label.setText("Shape   ");
        frame2.getContentPane().add(label);
        TextField.setPreferredSize(new java.awt.Dimension(180, 19));
        frame2.getContentPane().add(TextField);
        comment.setLayout(null);
        comment.setBorder(javax.swing.BorderFactory.createTitledBorder("Comment"));
        comment.setPreferredSize(new java.awt.Dimension(250, 130));
        jScrollPane1.setViewportView(TextPane);
        comment.add(jScrollPane1);
        jScrollPane1.setBounds(10, 20, 230, 100);
        frame2.getContentPane().add(comment);
        ok.setText("OK");
        ok.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });
        frame2.getContentPane().add(ok);
        cancel.setText("Cancel");
        cancel.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        frame2.getContentPane().add(cancel);
        frame2.setBounds(60, 50, 270, 230);


    }
    //************************************

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        TextField.setText(getName());
        TextPane.setText(getTextToolTip().substring(getName().length() + 2));
        frame2.setVisible(false);
    }

    private void okActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        setName(TextField.getText());
        setTextToolTip(getTextField() + ": " + TextPane.getText());
        frame2.setVisible(false);
    }

    private void item1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        if (PisCreate() == false) {
            PLadicionar();
        } else {
            PmostrarPanel();
        }
    }

    private void item2ActionPerformed(java.awt.event.ActionEvent evt) {
        java.awt.Component suprim = getParent();
        if (suprim instanceof LPaneProgram) {
            frame2.setVisible(false);
            getFrame().getprecedentL().getFrame().setVisible(false);
            getFrame().getprogramL().getFrame().setVisible(false);
            getFrame().setVisible(false);
            ((LPaneProgram) suprim).remove(this);
            ((LPaneProgram) suprim).repaint();
        }
    }

    private void item4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        if (frame.getIsConsecuent()) {
            frame.setIsConsecuent(false);
            if (isClon()) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/clon_ask.gif")));
            } else {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/askPreceding1.gif")));
            }
            iten4.setText("Add Consecuent");
            iten5.setEnabled(false);
            frame.hideConsecuent();
            frame.setVisible(false);
        } else {
            frame.setIsConsecuent(true);
            if (isClon()) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/clonask.gif")));
            } else {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/ask1.gif")));
            }
            iten4.setText("Remove Consecuent");
            iten5.setEnabled(true);
        }

    }

    private void item3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        clonar();
    }

    public void clonar() {
        if (iten3.getState()) {
            if (getIsConsecuent()) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/clonask1.gif")));
            } else {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/clon_ask.gif")));
            }
            clon = true;
        } else {
            if (getIsConsecuent()) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/ask1.gif")));
            } else {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/co/edu/usbcali/egrapico/images/askPreceding1.gif")));
            }
            clon = false;
        }
    }

    private void item5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        frame.setNameParent(nameParent + "." + getName());
        frame.setNameParentLabel(getName());
        frame.setNameParentParent(nameParent);
        frame.mostrarConsecuent();
    }

    private void item6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        frame.setNameParent(nameParent + "." + getName());
        frame.setNameParentLabel(getName());
        frame.setNameParentParent(nameParent);
        frame.mostrarPrecedent();
    }

    private void item7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        if (isCreate() == false) {
            Ladicionar();
        } else {
            mostrarPanel();
        }
    }
    //metodos pra feame de propiedades 

    public PanelAsk getFrame() {
        return frame;
    }

    public void setTextToolTip(String t) {
        toolTipText = t;
    }

    public String getTextToolTip() {
        return toolTipText;
    }

    public void PmostrarPanel() {
        frame2.setVisible(true);
        try {
            frame2.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
    }

    public void PLadicionar() {
        TextField.setText(getName());
        FrmPrincipal.addElementtoDesKtop(frame2);
        frame2.setVisible(true);
        try {
            frame2.setSelected(true);
        } catch (java.beans.PropertyVetoException e) {
        }
        ban1 = true;
    }

    public boolean PisCreate() {
        return ban1;
    }

    public String getTextField() {
        return TextField.getText();
    }

    public String getTextPane() {
        return TextPane.getText();
    }

    public void setTextPane(String i) {
        TextPane.setText(i);
    }
    //*************************************

    public void mostrarMenu(java.awt.Component c, int x, int y) {
        poput.show(c, x, y);
    }

    public void setNameParent(String name) {
        nameParent = name;
    }

    public String getNameParent() {
        return nameParent;
    }

    public void mostrarPanel() {
        frame.setNameParent(nameParent + "." + getName());
        frame.setNameParentLabel(getName());
        frame.setNameParentParent(nameParent);
        if (getIsConsecuent()) {
            frame.setTitle(nameParent + "." + getName());
            frame.setVisible(true);
            try {
                frame.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {
            }
        } else {
            frame.mostrarPrecedent();
        }
    }

    public void Ladicionar() {
        frame.setNameParent(nameParent + "." + getName());
        frame.setNameParentLabel(getName());
        frame.setNameParentParent(nameParent);
        if (getIsConsecuent()) {
            frame.setTitle(nameParent + "." + getName());
            FrmPrincipal.addElementtoDesKtop(frame);
            frame.setVisible(true);
            try {
                frame.setSelected(true);
            } catch (java.beans.PropertyVetoException e) {
            }
            ban = true;
        } else {
            frame.mostrarPrecedent();
        }
    }

    public boolean isCreate() {
        return ban;
    }

    public void setClon(boolean c) {
        clon = c;
        iten3.setState(clon);
    }

    public boolean isClon() {
        return clon;
    }

    public void setIsConsecuent(boolean b) {
        frame.setIsConsecuent(b);
    }

    public boolean getIsConsecuent() {
        return frame.getIsConsecuent();
    }

    public void changeItemMenu4() {
        iten4.setText("Add Consecuent");
        iten5.setEnabled(false);
    }

    public void hideConsecuent() {
        frame.hideConsecuent();
    }
}